<?php


namespace App\Http\Traits;


use Illuminate\Support\Arr;

class GlobalConstant
{

    //统一数组分隔符
    const DELIMITER_CHARACTER = ",";
    const IS_SUG = [
        1 => '是',
        2 => '否'
    ];
    const daysOfWeekCn = [
        'Sunday'    => '周日',
        'Monday'    => '周一',
        'Tuesday'   => '周二',
        'Wednesday' => '周三',
        'Thursday'  => '周四',
        'Friday'    => '周五',
        'Saturday'  => '周六'
    ];

    const SEX_LIST = [
        1 => '男',
        2 => '女',
    ];

    const ROLE_LIST = [
        ['value' => 1, 'text' => '老师'],
        ['value' => 2, 'text' => '学生'],
        ['value' => 3, 'text' => '爱心企业']
    ];

    const SEARCH_CATEGORY = [
        ['value' => 1, 'text' => '校区热度'],
        ['value' => 2, 'text' => '课程热度'],
        ['value' => 3, 'text' => '讨论热度'],
    ];

    const _STATUS = [
        0 => '禁用',
        1 => '正常'
    ];

    public static function setMarkerLabel($content)
    {
        $label              = new \stdClass();
        $label->content     = $content;
        $label->color       = '#319eec';
        $label->fontSize    = 13;
        $label->borderColor = '#000';
        $label->anchorX     = -60;
        $label->anchorY     = -84;
        return $label;
    }

    public static function setMarkerLabel2($content)
    {
        $label              = new \stdClass();
        $label->content     = $content;
        $label->color       = '#319eec';
        $label->fontSize    = 10;
        $label->borderColor = '#000';
        $label->anchorX     = -60;
        $label->anchorY     = -68;
        return $label;
    }

    public static function newSetMarkerLabel($content)
    {
        $label               = new \stdClass();
        $label->content      = $content;
        $label->color        = '#FFFFFF';
        $label->fontSize     = 12;
        $label->borderColor  = '#000';
        $label->anchorX      = -60;
        $label->anchorY      = -54;
        $label->bgColor      = '#0191FF';
        $label->padding      = 6;
        $label->borderRadius = 6;
        return $label;
    }

    public static function newSetMarkerLabel2($content)
    {
        $label              = new \stdClass();
        $label->content     = $content;
        $label->color       = '#319eec';
        $label->fontSize    = 10;
        $label->borderColor = '#000';
        $label->anchorX     = -60;
        $label->anchorY     = -68;
        return $label;
    }

    public static function getRoleMap($key = "ALL")
    {
        $ret = self::ROLE_LIST;
        if ($key === "ALL") {
            return $ret;
        }
        return Arr::get($ret, $key, false);
    }

    public static function getSearchCategoryMap($key = "ALL")
    {
        $ret = self::SEARCH_CATEGORY;
        if ($key === "ALL") {
            return $ret;
        }
        return Arr::get($ret, $key, false);
    }


    public static function formatAllTimeOrHour($timestamp, $hour = '', $type = 1)
    {
        if (empty($timestamp)) {
            return '';
        }
        if ($type == 1 && !empty($hour)) {
            return strtotime(date('Y-m-d', $timestamp) . ' ' . $hour);
        }
        return date('H:i', $timestamp);
    }


    public static function changeOrderBy($value = 1)
    {
        if ($value == 1) {
            return 'desc';
        }
        return 'asc';
    }

    public static function delimiterPrice($price)
    {
        return explode('.', $price);
    }


    public static function showOrderRefundBtn($order)
    {
        //已付款并且未提交过退款申请
        if ($order->status == 1 && $order->refund_status == 0) {
            return true;
        }
        return false;
    }

    public static function setStatusTip($status)
    {
        if ($status == 1) {
            return '待核销';
        }
        if ($status == 2) {
            return '已核销';
        }
        if ($status == 3) {
            return '已过期';
        }
        return '';
    }

    public static function resetArray($array)
    {
        if (empty($array)) return [];
        $temp = [];
        foreach ($array as $item) {
            if (!empty($item) || !is_null($item)) {
                $temp[] = $item;
            }
        }
        return $temp;
    }

}
